package JVM相关知识;

/**
 * @author coderFu
 * @create 2021/12/25
 */
public class MultiStaticDispatchDemo {
        static class QQ{}
        static class _360{}  //命名：字母数字下划线，数字不开头，所以_360
        public static class Father{

            public void hardChoice(Father father) {
                System.out.println("father choose father");
            }

            public void hardChoice(QQ arg){
                System.out.println("father choose qq");
            }
            public void hardChoice(_360 arg){
                System.out.println("father choose _360");
            }
        }
        public static class Son extends  Father{

            @Override
            public void hardChoice(QQ arg){
                System.out.println("son choose qq");
            }
            @Override
            public void hardChoice(_360 arg){
                System.out.println("son choose _360");
            }
        }
        public  static  void main(String[] args){
            Father father=new Father();   //father引用指向Father对象
            Father son2 = new Son();
            Father son=new Son();//son引用     编译类型是Father  运行类型是Son
            father.hardChoice(new _360());  //调用Father类的参数为_360类型的方法    打印 father choose _360
            father.hardChoice(new QQ());
            son.hardChoice(new QQ());    //调用Son类的参数为QQ类型的方法    打印 son choose qq
            System.out.println("================");
            //动态分派， 这是重写了 所以是调用子类的方法
            son2.hardChoice(new QQ());
            son2.hardChoice(new _360());
        }
    }

